package com.xjtu.mybatisplus.web.controller;

import com.xjtu.mybatisplus.common.JsonResponse;
import com.xjtu.mybatisplus.model.dto.ChatDTO;
import com.xjtu.mybatisplus.model.dto.CreateChatDTO;
import com.xjtu.mybatisplus.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@Controller
@RequestMapping("/api/llm")
public class LLMController {
    @Autowired
    private ChatService chatService;

    @PostMapping("/summary")
    @ResponseBody
    public JsonResponse summary(@RequestBody(required = false) String content) {
        return JsonResponse.success(chatService.summary(content));
    }

    @PostMapping("/chat")
    @ResponseBody
    public JsonResponse chat(@RequestBody ChatDTO chatDTO) {
        return JsonResponse.success(chatService.chat(chatDTO));
    }

    @PostMapping(value = "/streamChat", produces = "text/event-stream; charset=utf-8")
    @ResponseBody
    public SseEmitter streamChat(@RequestBody ChatDTO chatDTO) {
        return chatService.streamChat(chatDTO);
    }

    @PostMapping("/createChat")
    @ResponseBody
    public JsonResponse createChat(@RequestBody CreateChatDTO chatDTO) {
        return JsonResponse.success(chatService.createChat(chatDTO));
    }
}
